package com.hk.servlet.product;

import com.alibaba.fastjson.JSONObject;
import com.hk.model.ProductMenu;
import com.hk.model.vo.Result;
import com.hk.service.IProductMenuService;
import com.hk.service.IProductService;
import com.hk.service.impl.ProductMenuServiceImpl;
import com.hk.service.impl.ProductServiceImpl;
import com.hk.utils.CharacterEncoding;
import com.hk.utils.Tool;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @Author: zhe
 * @Date: 2021/6/21 11:25
 * @Statement: 通过Id删除产品
 */
@WebServlet("/product/FindByIdDeleteProduct")
public class FindByIdDeleteProductServlet extends HttpServlet {

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        CharacterEncoding.setCharacterEncodingResp(req,resp,"UTF-8");
        IProductService iProductService = new ProductServiceImpl();
        String id = Tool.nullToString(req.getParameter("id"));
        int intId = Tool.parseInt(id);
        int delete = iProductService.delete(intId);
        PrintWriter out = resp.getWriter();
        Result result = new Result();
        if (delete != 1) {
            result.setStatus(delete);
            result.setMessage("error");
        } else {
            result.setStatus(delete);
            result.setMessage("success");
        }
        String resultJSON = JSONObject.toJSONString(result);
        out.println(resultJSON);
        out.flush();
        out.close();

    }

}
